﻿using Blazored.SessionStorage;
using Furion.Logging;
using Masa.Blazor;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
using Microsoft.Extensions.Caching.Memory;

namespace TMV.Web.Core.Components
{
    public abstract class ProCompontentBase : ComponentBase
    {
       // private I18n? _languageProvider;
        
        [Inject]
        public IPopupService PopupService
        {
            get;
            set;
        }
		[Inject]
        IMemoryCache _memoryCache { get; set; }
		public string UserName { get; set; }
		private bool forceRender { get; set; } = false;
        [Inject]
        NavigationManager Navigation { get; set; } = default!;
        [CascadingParameter]
        private Task<AuthenticationState>? authenticationState { get; set; }
        protected async override Task OnInitializedAsync()
        {
			var usd = "";
			var islog = _memoryCache.TryGetValue("user", out usd);
			if (islog)
			{
				var authState = await authenticationState;
				var user = authState?.User;
                UserName = user.Identity.Name;
				//await PopupService.ToastSuccessAsync($"欢迎{user.Identity.Name} 进入系统！！");
				await InvokeAsync(StateHasChanged);
			}
			else
			{
				Navigation.NavigateTo($"{Navigation.BaseUri}pages/authentication/login-v2");
			}
		}
        public string T(string key)
        {
            return key;
        }
    }
}